<%--
  Created by IntelliJ IDEA.
  User: Gao
  Date: 2021/6/9
  Time: 14:36
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ include file="header.jsp"%>
<html>
<head>
    <title>Title</title>
</head>
<body>
   <%-- ${user}--%>
    <form id="formId" class="layui-form  layui-form-pane" >
        <input type="hidden" name="id" value="${user.id}"/>
        <div class="layui-form-item">
            <label class="layui-form-label">输入用户名</label>
            <div class="layui-input-block">
                <input type="text" value="${user.name}" name="name" lay-verify="title" autocomplete="off"  class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">输入年龄</label>
            <div class="layui-input-block">
                <input type="text" value="${user.age}" name="age" lay-verify="title" autocomplete="off"  class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">输入性别</label>
            <div class="layui-input-block">
                <c:if test="${user.gender=='男'}">
                    <input type="radio" name="gender" value="男" title="男" checked="">
                </c:if>
                <c:if test="${user.gender!='男'}">
                    <input type="radio" name="gender" value="男" title="男">
                </c:if>

                <c:if test="${user.gender=='女'}">
                    <input type="radio" name="gender" value="女" title="女" checked="">
                </c:if>
                <c:if test="${user.gender!='女'}">
                    <input type="radio" name="gender" value="女" title="女">
                </c:if>
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">请选择部门</label>
            <div class="layui-input-block">
                <select name="deptId">
                    <option value="">请选择部门</option>
                    <c:forEach items="${deptList}" var="dept">
                        <c:if test="${user.deptId==dept.id}">
                            <option value="${dept.id}" selected="true">${dept.name}</option>
                        </c:if>
                        <c:if test="${user.deptId!=dept.id}">
                            <option value="${dept.id}">${dept.name}</option>
                        </c:if>
                    </c:forEach>
                </select>
            </div>
        </div>
        <div class="layui-form-item">
            <input  class="layui-btn"  type="button" onclick="submitForm()" value="修改"/>
        </div>
    </form>


    <script>
        function submitForm() {
            $.post(
                '${path}/user/update',
                $('#formId').serialize(), // 封装form表单里面的数据 name=zhangsan
                function(jsonResult) {
                    if (jsonResult.ok){
                        // layer.msg(jsonResult.msg);

                        //当你在iframe页面关闭自身时获得当前弹出框的index索引
                        var index = parent.layer.getFrameIndex(window.name);
                        layer.msg(
                            jsonResult.msg,
                            {icon : 1, time : 2000},
                            function() {// msg消失之后触发的函数
                                // 关闭弹出层
                                parent.layer.close(index);
                                // 刷新父页面
                                window.parent.location.reload();
                            }
                        );
                    }
                }

            );
        }

    </script>

</body>
</html>
